// Author: 		ngohaibac@hocdelam.org
// Date:		20th Nov, 2009
// Hardware:	TMS320F28335
// Module:		EQep Module	

#ifndef DSP2833X_EQEPLIB_H_
#define DSP2833X_EQEPLIB_H_

#ifdef __cplusplus
extern "C" {
#endif

// Can be edited, ...
#define	QPOSInit_Val (Uint32)	0x00000000
#define QPOSMax_Val  (Uint32) 	0xFFFFFFFF

#define Encoder1_Rev	1024		// Pulses per rotation
#define	Encoder2_Rev	1024

//----------------------------------------
// Don't edit anything below here
//----------------------------------------
// Enum structure
enum EQep_Group { EQep1, EQep2 };
enum EQep_Interrupt_Group {EQep_INT=0, 
						   EQep_PCE, 
						   EQep_PHE, 
						   EQep_QDC, 
						   EQep_WTO, 
						   EQep_PCU, 
						   EQep_PCO, 
						   EQep_PCR, 
						   EQep_PCM, 
						   EQep_SEL, 
						   EQep_IEL, 
						   EQep_UTO};
						   
enum EQep_Control_Type { EQep_Position_Control, EQep_Speed_Control};

// Structure
struct Position_Instance {
	Uint32 Rotation;
	Uint32 Position;
};

struct Speed_Instance{
	Uint16 Direction;
	Uint32 Pre_Position;
	Uint32 Position;
	
};


// Declare some functions
void EQep_Init(enum EQep_Group EQep, enum EQep_Control_Type control_type);
void EQep_InitPositionCounter(enum EQep_Group EQep, Uint32 Position_Init);

void EQep_InitUnitTimeBase(enum EQep_Group EQep, Uint32 UTB_Period);
void EQep_SetUTBPeriod(enum EQep_Group EQep, Uint32 UTB_Period);

void EQep_InitEdgeCaptureUnit(enum EQep_Group EQep,Uint16 Clock_Prescaler, Uint16 Position_Prescaler );
void EQep_SetCaptureClock(enum EQep_Group EQep,Uint16 Clock_Prescaler);

void EQep_InitInterrupt(enum EQep_Group EQep, Uint16 Interrupt_Channels, PINT Interrupt_Fcn);
void EQep_ClearIntFlags(enum EQep_Group EQep, enum EQep_Interrupt_Group EQep_Int_Type);

#ifdef __cplusplus
}
#endif /* extern "C" */

#endif /*DSP2833X_EQEPLIB_H_*/
